<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png" @click="change('王五')">
    <!-- <HelloWorld msg="Welcome to Your Vue.js App"/> -->
    <SendMessage></SendMessage>
    <ReceiveMessage></ReceiveMessage>

    <GrandSon></GrandSon>

    <father-component></father-component>
  </div>
</template>

<script>
import SendMessage from './components/SendComponent.vue'
import ReceiveMessage from './components/ReceiveMessage.vue'
import GrandSon from './components/GrandSon.vue'
import FatherComponent from './components/FatherComponent.vue'
export default {
  name: 'App',
  components: {
    // HelloWorld
    SendMessage,
    ReceiveMessage,
    GrandSon,
    FatherComponent
  }, 
  created() {
    this.$on('sendMsg', msg => {
      console.log(`App 收到消息， msg = ${msg}`)
      this.msg = msg
    })
    // this.$on('sendMsg', msg => alert(msg))
  },
  methods: {
    sendMsg(msg) {
        console.log(`App 收到消息， msg = ${msg}`)
        // this.msg = msg
    },
    change(name) {
      // alert(`改变后的姓名：${name}`)
      this.username = name
      this.person.username = name
      // this.person = {
      //   username: name,
      //   age: 99
      // }
    }
  },
  data() {
    return {
      username: '张三',
      person: {
        username: '李四',
        age: 10
      }
    }
  },
  provide() {
    return {
      username: this.username,
      person: this.person
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
